package com.shujia.window

import org.apache.flink.streaming.api.scala._

object Demo03CountWindow {
  // 计数窗口
  def main(args: Array[String]): Unit = {

    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    env.setParallelism(1)


    val linesDS: DataStream[String] = env.socketTextStream("master", 8888)


    linesDS
      .map(line => (line.split(",")(0), 1))
      .keyBy(_._1)
      // 滚动的计数窗口 每5条数据统计一次
      //      .countWindow(5)
      // 滑动的计数窗口 每隔5条数据统计最近10条
      .countWindow(10, 5)
      .sum(1)
      .print()

    env.execute()
  }

}
